var BASE_URL = 'http://jinzhidata.com/v2'

function formatTime(timeVal, fmt) {
    timeVal = new Date(timeVal.replace(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}).*$/, '$1 $2 GMT+0000').replace(/-/g, '/'))
    var o = {
        "M+": timeVal.getMonth() + 1, //月份
        "d+": timeVal.getDate(), //日
        "h+": timeVal.getHours(), //小时
        "m+": timeVal.getMinutes(), //分
        "s+": timeVal.getSeconds(), //秒
        "q+": Math.floor((timeVal.getMonth() + 3) / 3), //季度
        "S": timeVal.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (timeVal.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}


$(function () {
    // 获取文章id
    var url = window.location.href
    var articleId = new RegExp(BASE_URL + "/article\\.html\\?articleId=(.*)").exec(url)[1]
    // 加载文章详情
    $.ajax({
        url: BASE_URL + "/article/" + articleId,
        type: "get",
        contentType: 'application/json',
        dataType: "json",
        success: function (response) {
            var data = response.data
            var html = '';
            html += '<div class="tit">';
            html += '<h2>' + data.articleTitle + '</h2>';
            html += '<span>'
            html += '<a>时间：<em>' + formatTime(data.createTime, "yyyy-MM-dd") + '</em></a>'
            html += '<a>作者：<em>' + data.articleAuthorName + '</em></a>'
            html += '</span>';
            html += "</div>";
            html += '<div class="txt">' + data.articleContent + "</div>";
            $(".zy_news_xqbox").html(html)
        }
    })
})

